package com.hq.thread.test3;

import java.util.Random;

/**
 * @ClassName SaleTicket
 * @Description TODO
 * @Author huangzl
 * @Date 2019/4/9 15:31
 * @Version 1.0
 **/
public class SaleTicket implements Runnable {

    public int total;
    public int count;

    public SaleTicket() {
        total = 100;
        count = 0;
    }

    @Override
    public void run() {
        while (total > 0) {
            synchronized (this) {
                if(total > 0) {
//                    try {
//                        Thread.sleep(new Random().nextInt(1000));
//                    } catch (InterruptedException e) {
//                        e.printStackTrace();
//                    }
                    count++;
                    total--;
                    System.out.println(Thread.currentThread().getName() + "\t当前票号：" + count);
                }
            }
        }
    }

    public static void main(String[] args) {
        SaleTicket st = new SaleTicket();
        for(int i=1; i<=5; i++) {
            new Thread(st, "售票点" + i).start();
        }

    }

}